/*
 * @Author: 谢陈洁
 * @Date: 2025-06-19 08:52:51
 * @LastEditors: 谢陈洁
 * @LastEditTime: 2025-07-23 16:08:46
 * @Description: file content
 */

interface TreeNode {
  id: number | string;
  parent_id: number | string;
  [key: string]: any;
}

export const buildTree = <T extends TreeNode>(data: T[]=[], parent_id: number | string = 0): T[] => {
  return data
    .filter(item => item.parent_id === parent_id)
    .map(item => ({
      ...item,
      label: item.title,
      value: item.id,
      meta: {
        sort: item.sort,
        icon: item.icon,
        title: item.title,
        hidden: item.status ? false : false,
      },
      children: buildTree(data, item.id)
    }))
};
